<template>
    <div class="menu-container">
        <div class="menu-card">
            <div class="menu-header">
                <h1 class="menu-title">Orbrawl</h1>
                <p v-if="showInfo" class="menu-subtitle">战斗竞技游戏</p>
            </div>

            <div class="menu-content">
                <div class="menu-buttons">
                    <button class="menu-button primary" @click="startGame">
                        <el-icon>
                            <VideoPlay />
                        </el-icon>
                        <span>开始游戏</span>
                    </button>

                    <button class="menu-button warning" @click="openFriends">
                        <el-icon>
                            <UserFilled />
                        </el-icon>
                        <span>好友列表</span>
                    </button>

                    <button class="menu-button info" @click="openSettings">
                        <el-icon>
                            <Setting />
                        </el-icon>
                        <span>设置</span>
                    </button>
                </div>
            </div>

            <div class="menu-footer">
                <div class="user-info">
                    <div class="user-avatar" @click="openProfile">
                        <img
                            :src="
                                userStore.photo ||
                                'https://www.helloimg.com/i/2024/12/22/6767fd5a3cf23.jpg'
                            "
                            alt="用户头像"
                        />
                    </div>
                    <div class="user-name">{{ userStore.username || '未登录' }}</div>
                </div>
                <div v-if="showInfo" class="game-info">
                    <div>{{ gameInfo.version }}</div>
                    <div>{{ gameInfo.developer }}</div>
                </div>
                <div class="info-toggle" @click="toggleInfo">
                    <el-icon>
                        <InfoFilled />
                    </el-icon>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
    import { ref } from 'vue'
    import { InfoFilled, Setting, UserFilled, VideoPlay } from '@element-plus/icons-vue'
    import { useRouter } from 'vue-router'
    import { useUserStore } from '@/stores/user'

    const router = useRouter()
    const userStore = useUserStore()
    const showInfo = ref(false)

    // 游戏信息
    const gameInfo = {
        title: 'Orbrawl',
        version: 'Beta 1.0.0',
        developer: '©LZH',
    }

    const startGame = () => {
        router.push('/mode/')
    }

    const openProfile = () => {
        router.push('/profile/')
    }

    const openFriends = () => {
        router.push('/friend/')
    }

    const openSettings = () => {
        router.push('/settings/')
    }

    const toggleInfo = () => {
        showInfo.value = !showInfo.value
    }
</script>

<style scoped>
    .menu-container {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        width: 100vw;
    }

    .menu-card {
        width: 500px;
        background-color: rgba(0, 0, 0, 0.7);
        border-radius: 12px;
        padding: 30px;
        box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
        border: 1px solid rgba(255, 215, 0, 0.3);
        color: #fff;
        animation: fadeIn 0.5s ease-in-out;
        transform: scale(1);
        transition: transform 0.3s ease;
        display: flex;
        flex-direction: column;
        height: 600px;
    }

    .menu-card:hover {
        transform: scale(1.01);
        box-shadow: 0 0 40px rgba(255, 215, 0, 0.5);
    }

    .menu-header {
        text-align: center;
        margin-bottom: 40px;
        padding-bottom: 20px;
        border-bottom: 1px solid rgba(255, 215, 0, 0.3);
    }

    .menu-title {
        font-size: 4.5rem;
        color: white;
        margin: 0;
        text-shadow: 0 0 10px #fffb00;
        font-family: 'consolas', monospace;
        font-style: italic;
        user-select: none;
        letter-spacing: 2px;
    }

    .menu-subtitle {
        font-size: 1.2rem;
        color: rgba(255, 255, 255, 0.7);
        margin-top: 5px;
        animation: fadeIn 0.5s ease-in-out;
    }

    .menu-content {
        flex: 1;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .menu-buttons {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1.5rem;
        width: 100%;
    }

    .menu-button {
        width: 100%;
        height: 60px;
        font-size: 1.2rem;
        transition: all 0.3s ease;
        padding: 0 20px;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: rgba(0, 0, 0, 0.5);
        border: none;
        border-radius: 8px;
        color: white;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .menu-button::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
        transform: translateX(-100%);
        transition: transform 0.5s;
    }

    .menu-button:hover::before {
        transform: translateX(100%);
    }

    .menu-button:hover {
        transform: translateY(-3px);
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    }

    .menu-button.primary {
        border: 2px solid #409eff;
        box-shadow: 0 0 10px rgba(64, 158, 255, 0.3);
    }

    .menu-button.warning {
        border: 2px solid #e6a23c;
        box-shadow: 0 0 10px rgba(230, 162, 60, 0.3);
    }

    .menu-button.info {
        border: 2px solid #909399;
        box-shadow: 0 0 10px rgba(144, 147, 153, 0.3);
    }

    .menu-button.primary:hover {
        box-shadow: 0 5px 15px rgba(64, 158, 255, 0.5);
    }

    .menu-button.warning:hover {
        box-shadow: 0 5px 15px rgba(230, 162, 60, 0.5);
    }

    .menu-button.info:hover {
        box-shadow: 0 5px 15px rgba(144, 147, 153, 0.5);
    }

    .menu-footer {
        margin-top: 40px;
        padding-top: 20px;
        border-top: 1px solid rgba(255, 215, 0, 0.3);
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .user-info {
        display: flex;
        align-items: center;
    }

    .user-avatar {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        overflow: hidden;
        border: 2px solid #ffd700;
        cursor: pointer;
        transition: all 0.3s;
    }

    .user-avatar:hover {
        transform: scale(1.1);
        box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    }

    .user-avatar img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .user-name {
        margin-left: 10px;
        font-size: 0.9rem;
        color: rgba(255, 255, 255, 0.8);
    }

    .game-info {
        font-size: 0.8rem;
        color: rgba(255, 255, 255, 0.5);
        text-align: right;
        animation: fadeIn 0.5s ease-in-out;
    }

    .info-toggle {
        cursor: pointer;
        width: 30px;
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: rgba(255, 215, 0, 0.7);
        transition: all 0.3s;
    }

    .info-toggle:hover {
        color: #ffd700;
        transform: rotate(180deg);
    }

    @keyframes fadeIn {
        from {
            opacity: 0;
            transform: translateY(-10px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
</style>
